package com.qf.flash.mvp.presenter;

import com.qf.flash.http.HttpManager;
import com.qf.flash.http.response.ScriptDetailResponse;
import com.qf.flash.model.ScriptRoleBean;
import com.qf.flash.mvp.contract.ScriptDetailContract;
import com.qf.flashlib.base.BasePresenter;
import com.qf.flashlib.base.BaseSubscriber;
import com.qf.flashlib.util.RxUtils;

import java.util.List;

/**
 * 描述: 组队详情
 * 2020/3/24 14:20
 */
public class ScriptDetailPresenter extends BasePresenter<ScriptDetailContract.View> implements ScriptDetailContract.Presenter {

    @Override
    public void getScriptDetail(String id) {
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .SCRIPT_DETAIL(id)
                .compose(RxUtils.handleResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<ScriptDetailResponse>(mRootView) {
                    @Override
                    public void onSuccess(ScriptDetailResponse response) {
                        mRootView.setScriptDetail(response);
                    }
                })
        );
    }

    @Override
    public void getScriptRole(String id) {
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .SCRIPT_ROLE(id)
                .compose(RxUtils.handleResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<List<ScriptRoleBean>>(mRootView) {
                    @Override
                    public void onSuccess(List<ScriptRoleBean> response) {
                        mRootView.setScriptRole(response);
                    }
                })
        );
    }
}
